package com.ycsj.goldmedalnewconcept.master.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ycsj.common.base.BaseActivity;
import com.ycsj.common.manager.BannerManager;
import com.ycsj.common.manager.PickChooseManager;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.bean.EventInfo;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherEventPeoplesActivity;
import com.youth.banner.Banner;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 校长端活动详情
 * Created by Administrator on 2019/4/19 0019.
 */

public class MaseterEventDetailsActivity  extends BaseActivity {


    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.tv_num)
    TextView tvNum;

    //活动名称
    @BindView(R.id.tv_name)
    TextView tvName;

    // 新概念1班,新概念2班
    @BindView(R.id.tv_target)
    TextView tvTarget;

    //时间
    @BindView(R.id.tv_time)
    TextView tvTime;

    //地址
    @BindView(R.id.tv_address)
    TextView tvAddress;
    //活动内容
    @BindView(R.id.tv_content)
    TextView tvContent;

    //查看报名名单
    @BindView(R.id.bt_look_people)
    Button btLookPeople;

    @BindView(R.id.ll_conent)
    LinearLayout llConent;

    @BindView(R.id.rl_loading)
    RelativeLayout rlLoading;

    //页面传递的对象
    private EventInfo.ListBean info;


    //报名活动的请求参数
    private String acc, role, apptoken;




    @Override
    protected int getContentLayout() {
        return R.layout.parent_activity_event_details;
    }

    @Override
    protected void init() {

        //初始化状态栏
        initStateBar();

        //获取Intent对象
        initIntent();

        //设置页面其它的数据
        setPageData();
    }

    /**
     * 获取Intent对象
     */
    private void initIntent() {
        info = (EventInfo.ListBean) getIntent().getSerializableExtra("data");
    }

    /**
     * 设置轮播图的数据
     */
    private void setBanner() {
        if (info != null) {
            final List<String> bannerUrls = new ArrayList<>();
            if (!TextUtils.isEmpty(info.getPicture1())) {
                bannerUrls.add(info.getPicture1());
            }
            if (!TextUtils.isEmpty(info.getPicture2())) {
                bannerUrls.add(info.getPicture2());
            }

            if (!TextUtils.isEmpty(info.getPicture3())) {
                bannerUrls.add(info.getPicture3());
            }

            if (!TextUtils.isEmpty(info.getPicture4())) {
                bannerUrls.add(info.getPicture4());
            }
            if (!TextUtils.isEmpty(info.getPicture5())) {
                bannerUrls.add(info.getPicture5());
            }
            if (!TextUtils.isEmpty(info.getPicture6())) {
                bannerUrls.add(info.getPicture6());
            }
            if (!TextUtils.isEmpty(info.getPicture7())) {
                bannerUrls.add(info.getPicture7());
            }
            if (!TextUtils.isEmpty(info.getPicture8())) {
                bannerUrls.add(info.getPicture8());
            }
            if (!TextUtils.isEmpty(info.getPicture9())) {
                bannerUrls.add(info.getPicture9());
            }

            if (bannerUrls.size() == 0) {
                List<Integer> imgs = new ArrayList<>();
                imgs.add(R.drawable.base_event_def);
                //证明没有上传图片,那么现实默认的本地图片
                BannerManager.setDataLocal(banner, imgs, Transformer.ZoomIn);
            } else {
                BannerManager.setData(banner, true, bannerUrls, Transformer.ZoomIn);
                //设置点击事件
                banner.setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(int position) {
                        PickChooseManager.startShowBigActivity(MaseterEventDetailsActivity.this, bannerUrls, position);
                    }
                });
            }
        }
    }

    /**
     * 设置页面其它显示数据
     */
    private void setPageData() {

        tvTitle.setText("活动报名");

        rlLoading.setVisibility(View.GONE);

        llConent.setVisibility(View.VISIBLE);

        if (info != null) {

            //设置轮播图的数据
            setBanner();

            //轮播图的标题
            tvName.setText(info.getTag());

            //报名人数
            if (TextUtils.isEmpty(info.getCount())) {
                tvNum.setText("0");
            } else {
                tvNum.setText(info.getCount());
            }

            //活动对象
            tvTarget.setText(info.getTarget());

            //活动时间
            tvTime.setText(info.getBegintime() + "  至  " + info.getEndtime());

            //活动地点
            tvAddress.setText(info.getAddress());

            //活动简介
            tvContent.setText(info.getContent());

            //根据是否有人报名来设置报名按钮的背景以及是否可点击的状态
            if("0".equals(info.getCount())){
                //没有人报名
                btLookPeople.setText("报名名单");
                btLookPeople.setEnabled(false);
                btLookPeople.setBackgroundResource(R.drawable.parent_bt_nolook_people);
            }else{
                //有人报名
                btLookPeople.setText("报名名单");
                btLookPeople.setEnabled(true);
                btLookPeople.setBackgroundResource(R.drawable.parent_bt_look_people);
            }
        }
    }

    /**
     * 点击事件
     *
     * @param v
     */
    @OnClick({R.id.iv_back, R.id.bt_look_people})
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            //返回
            finish();
        } else if (id == R.id.bt_look_people) {
            //报名名单
            TeacherEventPeoplesActivity.goActivity(this,info.getRowId()+"",info.getUserId());
        }
    }
}
